home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Shareware Grab Bag
/
Shareware Grab Bag.iso
/
007
/
pctecap.arc
/
MEMINIT.ASM
< prev
next >
Wrap
Assembly Source File
|
1986-03-15
|
9KB
|
252 lines
page 60,132
title 'MEMINIT - Obtain all available user memory'
subttl 'Version 1.0 October, 1983'
stack SEGMENT para stack 'STACK'
db 16 dup('stack ')
stack ENDS
data SEGMENT at 40H ; DOS data segment in low memory
org 13H
memory_size dw ; total memory size (K bytes)
io_ram_size dw ; memory in I/O channel (K bytes)
data ENDS
code SEGMENT byte
assume cs:code,ds:code,ss:stack
original_memory_size dw ? ;
original_io_memory dw ? ; all sizes stored in 'K' bytes
additional_memory dw ? ;
starting_memory_block dw ? ; location of program's PSP
command_proc_PSP dw ? ; location of command's PSP
; (PSP=program segment prefix)
crlf db 10,13,'$'
msg1 db 'Original memory used:'
msg1data db ' K bytes$'
msg2 db ' Total memory added:'
msg2data db ' K bytes$'
msg3 db ' Total memory:'
msg3data db ' K bytes$'
heading db 10,13,'MEMINIT - Version 1.00',10,13
db 10,13,'$'
.RADIX 16
dosfunction MACRO function_number
mov ah,function_number
int 21
endm
print MACRO msg, msgdata
mov bx,offset msgdata
call convert_to_ascii
mov dx,offset msg
dosfunction 9
mov dx,offset crlf
dosfunction 9
endm
convert_to_ascii PROC far
;-------------------------
; convert_to_ascii converts a binary number
; in AX to ascii display characters
push dx ; save register values
push si
mov cx,6 ; initialize destination with spaces
fill_buff:
mov byte ptr [bx],' '
inc bx
loop fill_buff
mov si,0A
do_divide:
sub dx,dx
div si ; divide AX by 10
add dx,'0' ; convert remainder to ASCII digit
dec bx
mov [bx],dl ; store this char in the string
inc cs ; count converted character
or ax,ax ; all done?
jnz do_divide ; no: get next digit
pop si ; Restore registers
pop dx
ret ; and exit
convert_to_ascii ENDP
update_memory_control_words PROC far
;-------------------------------------
assume cs:code,ds:data,ss:stack
push es
push ds
mov ax,data ; Set up DS to reference DOS
mov ds,ax ; variables in low memory
mov ax,starting_memory_block
dec ax ; AX points to memory control block
; starting at that spot, look for
; the end of the memory links
; ( byte zero = 'Z' )
find_ending_link:
mov es,ax ; set up address of mem control blk
cmp byte ptr es:[0],5AH ; Is this the ending link?
jz found_the_link
add ax,es:[3] ; link to next area
inc ax
jmp find_ending_link
found_the_link: ; now update length field of this
; last mem control block to
; include the additional memory
mov bx,memory_size
mov cl,6
shl bx,cl ; convert to K bytes
sub bx,ax
dec bx
mov es:[3],bx
pop ds ; restore registers
pop es
clc ; indicate normal return (no error)
ret
update_memory_control_words ENDP
memory_size_initialize PROC far
;-------------------------------
assume ds:code,cs:code,es:data,ss:stack
mov cs:starting_memory_block,ds
push ds
sub ax,ax
push ax
mov ax,code
mov ds,ax
mov dx,es:[0C] ; COMMAND's program segment prefix
mov command_proc_PSP,dx ; which we will use to fix up
; DOS release 1.1
mov dx,offset heading ; put out introductory heading
dosfunction 9
mov bx,data ; get ROM-initialized
mov es,bx ; memory size
mov ax,memory_size ; specifications
mov original_memory_size,ax
mov bx,io_ram_size
mov original_io_memory,bx
mov cl,6
shl ax,cl ; convert from K bytes
mov bx,0
memory_loop:
cmp ax,0a000 ; check if greater than
je initialize_memory ; 640K ..if so then end
mov ds,ax
mov [bx],ax ; write segment # into byte
mov cx,[bx] ; read segment # from byte
cmp ax,cx ; if equal..memory exists
jne initialize_memory ; else no more user memory
mov ax,ds
add ax,400 ; increment segment # by 16K
jmp memory_loop ; and try some more
initialize_memory: ; write data into memory so that
; parity errors do no occur upon
; access of new memory
mov bx,memory_size
mov cl,6
shl bx,cl
push ax ; save the value for AX containing
pop dx ; the new top of memory.
mov ax,0 ;
cld ; set direction=forward
store_initial_value:
cmp bx,dx
je end_of_user_memory ; go through newly allocated mem
mov es,bx ; and write a pattern of X'0000'
mov cx,03fff ; into each word. This will protect
mov di,0 ; against a fatal parity error later
rep stosw ; when mem is read without being
add bx,400 ; written. (Done 16K bytes at a time.)
jmp store_initial_value
end_of_user_memory:
push dx ; restore the value for AX
pop ax
mov cl,6 ; convert from bytes to
shr ax,cl ; K bytes
mov bx,code ; calculate changed memory
mov ds,bx ; sizes and ..
mov bx,data
mov es,bx
mov memory_size,ax ; store back ..
sub ax,original_memory_size ; into DOS variables
mov additional_memory,ax
add ax,original_io_memory
mov io_ram_size,ax
dosfunction 30 ; check DOS version
cmp al,00
je modify_DOS1 ; pre 2.0 DOS...handle special
call update_memory_control_words ; routine for DOS 2.0
jmp display_results
modify_DOS1:
push ds
mov dx,command_proc_PSP ; get ready to store new
mov ds,dx ; memory size in COMMAND's
mov dx,memory_size ; stored variable.
mov cl,6
shl dx,cl
mov ds:[452],dx ; location of memory size on
pop ds ; DOS release 1.1
display_results:
mov ax,original_memory_size
print msg1,msg1data
mov ax,additional_memory
print msg2,msg2data
mov ax,memory_size
print msg3,msg3data
exit:
ret
memory_size_initialize ENDP
code ENDS
END memory_size_initialize